﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entidades.Karaoke;
using System.Configuration;
using System.Data.SqlClient;

namespace Datos.Karaoke
{
    public class KarMesaDAL
    {
        public static string cnx = ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString();

        public static List<KarMesa> ListarMesa( )
        {
            SqlConnection con = new SqlConnection(cnx);
            SqlCommand com = new SqlCommand("SELECT [NroMesa], [Estado] FROM [Kar_Mesa]", con);
            com.CommandType = System.Data.CommandType.Text;
            try
            {
                con.Open();
                SqlDataReader dr = com.ExecuteReader();
                List<KarMesa> lista = new List<KarMesa>();
                KarMesa obj = null;
                while (dr.Read())
                {
                    obj = new KarMesa();

                    obj.NroMesa = Convert.ToInt32(dr["NroMesa"].ToString());
                    obj.Estado = (Convert.ToBoolean(dr["Estado"]) ? 1 : 0);
                    obj.strEstado = (obj.Estado == 0 ? "Libre" : "Activado");

                    lista.Add(obj);
                }
                dr.Close();

                return lista;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }
        }

        public static KarMesa ObtenerMesa(int NroMesa)
        {  
            SqlConnection con = new SqlConnection(cnx);
            SqlCommand com = new SqlCommand("SELECT [NroMesa], [Estado] FROM [Kar_Mesa] where [NroMesa]= " + NroMesa, con);

            com.CommandType = System.Data.CommandType.StoredProcedure;
            try
            {
                con.Open();
                SqlDataReader dr = com.ExecuteReader();
                KarMesa  obj = null;
                while (dr.Read())
                {
                    obj = new KarMesa();

                    obj.NroMesa = Convert.ToInt32(dr["NroMesa"].ToString());
                    obj.Estado = (Convert.ToBoolean(dr["Estado"]) ? 1 : 0);
                    obj.strEstado = (obj.Estado == 0 ? "Inactivo" : "Activo");

                }
                dr.Close();

                return obj;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }
        }


    }
}
